package com.jic.member.impl;

import java.lang.Long;
import java.util.Date;
import java.util.List;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.member.entity.MemberType;
import com.jic.member.mapper.MemberTypeMapper;
import com.jic.member.request.MemberTypeRequest;
import com.jic.member.service.MemberTypeService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 会员类型字典表
 * @author : 
 * @email : 
 * @since : 2020-01-17 10:33:01
 * @version : v1.0.0
 */
@Service
public class MemberTypeServiceImpl implements MemberTypeService{

    @Autowired
    private MemberTypeMapper memberTypeMapper;

    @Override
    public long insert(MemberTypeRequest memberTypeRequest) {

        memberTypeRequest.setDeleteFlag(0);
        memberTypeRequest.setDeptId(memberTypeRequest.getAdminOperate().getDeptId());
        memberTypeRequest.setCreator( memberTypeRequest.getAdminOperate().getOperator());
        memberTypeRequest.setCreatorName(memberTypeRequest.getAdminOperate().getOperateName());
        memberTypeRequest.setCreateTime(new Date());

        long flag = memberTypeMapper.insert(memberTypeRequest);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return memberTypeMapper.delete(id);
    }

    @Override
    public long update(MemberTypeRequest memberTypeRequest) {
        memberTypeRequest.setUpdater( memberTypeRequest.getAdminOperate().getOperator());
        memberTypeRequest.setUpdaterName(memberTypeRequest.getAdminOperate().getOperateName());
        memberTypeRequest.setUpdateTime(new Date());
        return memberTypeMapper.update(memberTypeRequest);
    }

    @Override
    public MemberType queryByPrimaryKey(Long id){
        return memberTypeMapper.queryByPrimaryKey(id);
    }

    @Override
    public MemberType getMemberTypeInfo(MemberTypeRequest memberTypeRequest){
        return memberTypeMapper.getMemberTypeInfo(memberTypeRequest);
    }

    @Override
    public List<MemberType> query(MemberType memberType){
        return memberTypeMapper.query(memberType);
    }

    @Override
    public PageResult<MemberType> queryPage(MemberTypeRequest memberTypeRequest, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        memberTypeRequest.setDeptId(memberTypeRequest.getAdminOperate().getDeptId());
        List<MemberType> list = memberTypeMapper.queryPage(startIndex, pageQuery.getLimit(), memberTypeRequest);
        long count = memberTypeMapper.queryPageCount(memberTypeRequest);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}
